package com.ruoyi.assest.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.assest.domain.Zcrz;
import com.ruoyi.assest.service.IZcrzService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资产台账Controller
 *
 * @author ruoyi
 * @date 2024-12-04
 */
@RestController
@RequestMapping("/zctz/zctz")
public class ZcrzController extends BaseController
{
    @Autowired
    private IZcrzService zcrzService;

    /**
     * 查询资产台账列表
     */
    @PreAuthorize("@ss.hasPermi('zctz:zctz:list')")
    @GetMapping("/list")
    public TableDataInfo list(Zcrz zcrz)
    {
        System.out.println("第一个");
        startPage();
        List<Zcrz> list = zcrzService.selectZcrzList(zcrz);
        return getDataTable(list);
    }

    /**
     * 导出资产台账列表
     */
    @PreAuthorize("@ss.hasPermi('zctz:zctz:export')")
    @Log(title = "资产台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Zcrz zcrz)
    {
        List<Zcrz> list = zcrzService.selectZcrzList(zcrz);
        ExcelUtil<Zcrz> util = new ExcelUtil<Zcrz>(Zcrz.class);
        util.exportExcel(response, list, "资产台账数据");
    }

    /**
     * 获取资产台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('zctz:zctz:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zcrzService.selectZcrzById(id));
    }

    /**
     * 新增资产台账
     */
    @PreAuthorize("@ss.hasPermi('zctz:zctz:add')")
    @Log(title = "资产台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Zcrz zcrz)
    {
        return toAjax(zcrzService.insertZcrz(zcrz));
    }

    /**
     * 修改资产台账
     */
    @PreAuthorize("@ss.hasPermi('zctz:zctz:edit')")
    @Log(title = "资产台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Zcrz zcrz)
    {
        return toAjax(zcrzService.updateZcrz(zcrz));
    }

    /**
     * 删除资产台账
     */
    @PreAuthorize("@ss.hasPermi('zctz:zctz:remove')")
    @Log(title = "资产台账", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zcrzService.deleteZcrzByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('zctz:zctz:query')")
    @GetMapping("/{jname}")
    public AjaxResult list2(@PathVariable("jname") String jname)
    {
        System.out.println("第二个");
        System.out.println(jname);
        startPage();
       List<Zcrz> list = new ArrayList<>();
        return success(list);
    }


}
